import { View, Image } from '@tarojs/components'
import photo from '../../assets/photo.png'
import "taro-ui/dist/style/components/button.scss" // 按需引入
import './index.scss'
import GlobalFooter from '../../components/GlobalFooter'
import {AtButton} from "taro-ui";
import Taro from "@tarojs/taro";
import questionResult from '../../question/question_result.json'
import questions from '../../question/question.json'
import {getMaxScore} from '../../utils/bilUtils'

/**
 * 答案页
 */
export default () => {
  //获取答题页传过来的参数
  const answerList = Taro.getStorageSync("answerList");
  if(!answerList || answerList.length < 1){
    Taro.showToast({
      title:"答案为空",
      icon:"error",
      duration:3000,
    })
  }

  //根据算法获取答案
  const result = getMaxScore(answerList,questions,questionResult);

    return (

      <View className='resultPage'>
        <View className='at-article__h1 text1'>
          {result.resultName}
        </View>
        <View className='at-article__h2 text2'>
          {result.resultDesc}
        </View>
        <AtButton className='btn' type='primary' circle onClick={() =>{
          Taro.reLaunch({
            url: '/pages/index/index',
          })
        }}>返回主页</AtButton>
        <Image className='imagePhoto' src={photo}/>
        <GlobalFooter></GlobalFooter>

      </View>

    )
}
